package com.zznode.redsun.commons.dto;

import java.math.BigDecimal;

import com.zznode.csp.domain.commons.util.DomainBeanUtils;
import com.zznode.redsun.smartcrm.model.Product;
import com.zznode.redsun.smartcrm.model.Provider;

public class ProductDto extends BaseDto {
	private Long providerId;
	private String providerName;
	private String model;
	private BigDecimal price;

	public static ProductDto create(Product entity) {
		ProductDto product = new ProductDto();
		product.setParentField(entity);
		product.setProviderId(entity.getProvider().getId());
		product.setProviderName(entity.getProvider().getName());
		product.setModel(entity.getModel());
		product.setPrice(entity.getPrice());

		return product;
	}

	public Product convert() {
		Product entity = new Product();
		update(entity);
		return entity;
	}

	public void update(Product entity) {
		super.update(entity);
		if (null == entity.getProvider() || !this.providerId.equals(entity.getProvider().getId())) {
			entity.setProvider(DomainBeanUtils.create(Provider.class, providerId));
		}
		entity.setModel(model);
		entity.setPrice(price);
	}

	public Long getProviderId() {
		return providerId;
	}

	public void setProviderId(Long providerId) {
		this.providerId = providerId;
	}

	public String getProviderName() {
		return providerName;
	}

	public void setProviderName(String providerName) {
		this.providerName = providerName;
	}

	public String getModel() {
		return model;
	}

	public void setModel(String model) {
		this.model = model;
	}

	public BigDecimal getPrice() {
		return price;
	}

	public void setPrice(BigDecimal price) {
		this.price = price;
	}

}
